
<%@ page import="com.surelution.projects.crm.GasType" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:javascript library="jquery" plugin="jquery"/>
        <r:require module="jquery-ui"/>
        <r:layoutResources/>
        <title><g:message code="default.selectmap.label" args="[entityName]" /></title>
		<style type="text/css">
			html{height:100%}
			body{height:100%;margin:0px;padding:0px}
			#container{height:95%}
		</style>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
		<script type="text/javascript">
			var lng,lat;

			var map,mapType,zoom;
			function initMap() {
				map = new BMap.Map("container_map");
				map.mapType = BMAP_NORMAL_MAP;
				var center = new BMap.Point(120.741578,30.748013);
				map.centerAndZoom(center, 13);
				map.addControl(new BMap.NavigationControl());
				map.addControl(new BMap.MapTypeControl({mapTypes:[BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP, BMAP_HYBRID_MAP]}));
				var menu = new BMap.ContextMenu();
				var txtMenuItem = [
				                   {
					                    text:'添加中石油加油站',
					                    callback:function(p){
					                    	lng = p.lng;					                    
					    					lat = p.lat;
					                    	addOwnStation(1,lng,lat);
					                    }
				                   },
				                   {
					                    text:'添加竞争对手',
					                    callback:function(p){
					                    	lng = p.lng;					                    
					    					lat = p.lat;
					                    	addOwnStation(2,lng,lat);
				                    	}
				                   },
				                   {
					                    text:'添加客户',
					                    callback:function(p){
					                    	lng = p.lng;					                    
					    					lat = p.lat;
					                    	addOwnStation(3,lng,lat);
				                    	}
				                   },
				                   {
					                    text:'重置中石油加油站',
					                    callback:function(p){
					                    	lng = p.lng;					                    
					    					lat = p.lat;
					                    	addOwnStation(4,lng,lat);
					                    }
					                },
					                {
					                    text:'重置竞争对手',
					                    callback:function(p){
					                    	lng = p.lng;					                    
					    					lat = p.lat;
					                    	addOwnStation(5,lng,lat);
					                    }
					                },
				                   {
					                    text:'重置客户位置',
					                    callback:function(p){
					                    	lng = p.lng;					                    
					    					lat = p.lat;
					                    	addOwnStation(6,lng,lat);
					                    }
					                },
				                   ];

				for(var i=0; i < txtMenuItem.length; i++){
					if(txtMenuItem[i]){
					  menu.addItem(new BMap.MenuItem(txtMenuItem[i].text,txtMenuItem[i].callback,100));
					}
				}
				map.addContextMenu(menu);
			}

			
			$(document).ready(function() {initMap()});
	    	function getMapType() {
				if(map.mapType == BMAP_HYBRID_MAP) {
					mapType = "BMAP_HYBRID_MAP"
				} else if(map.mapType == BMAP_NORMAL_MAP) {
					mapType = "BMAP_NORMAL_MAP"
				} else if(map.mapType == BMAP_SATELLITE_MAP) {
					mapType = "BMAP_SATELLITE_MA"
				}	   
				return mapType; 	
			}
	    	function addMarker(x, y){
				var myIcon = new BMap.Icon(
						"http://api.map.baidu.com/img/markers.png" , 
						new BMap.Size(23, 25), 
						{offset: new BMap.Size(32, 32),size:new BMap.Size(23, 25)}
				);
				var point = new BMap.Point(x, y);
				var marker = new BMap.Marker(point, {icon: myIcon}); 
				map.addOverlay(marker);
			}

			function addOwnStation(useSelect,lng,lat) {
				var type = getMapType();
				var zoom = map.getZoom();
				var u = "../overview/select?useSelect=" + useSelect + "&lng=" + lng + "&lat=" + lat + "&type=" + type + "&zoom=" + zoom;
				document.location.href=u;
			}
	    	</script>
    </head>
    <body>
    <div id="title" style="height:5%;text-align:center;font-size:16px;color:#0f39ef;position: relative;top: 7px;">
    		请在地图任意位置右击，并选择相应功能进行地图定位！
    	</div>
		<div id="container_map"></div>
    </body>
</html>
